<?php
namespace Waimai\Controller;
class SetController extends Controller {
	//店铺列表
	public function index(){
		//读取微信公众号id
		$wxid = Db::table('set')->where('username',$_SESSION['username'])->pluck('id');
		$_SESSION['wxid'] = $wxid;
		View::with('wxid',$wxid);		
		$data = Db::table('shop')->get();
		View::with('data',$data)->make();
	}

	//添加店铺
	public function add() {
		
		if (IS_POST) {
			$_POST['wxid'] = $_SESSION['id'];
			if(Db::table('shop')->insert($_POST))
			{
				View::ajax(array('code'=>0,'message'=>'添加成功'));
			}
			else{
				View::ajax(array('code'=>1,'message'=>'设置失败'));
			}
		} else {
			View::make();
		}
	}
	
	public function getShop() {

		$data = Db::table('shop') -> where('wxid', $_POST['wxid']) -> get();
		View::ajax($data);
	}



}
